<?php

/** 
 * 
 */
class School_mdl extends MY_Model {
	
	private $schoolList = array();
	
	/**
	 */
	public function __construct() {
		parent::__construct ();
		$this->load->database();
		$this->_table = parent::T_SCHOOL;
	}
	
	public function getSchoolList($where=array(),$where_in=array()){
		if( empty($this->schoolList) ){ 
			if(!empty($where_in)){ 
					$this->schoolList = $this->getListHaveWhereIn('*',$where,$where_in); 
			}else{
				$this->schoolList = $this->getList('*',$where);
			}
		
			$this->schoolList = array_combine( array_column($this->schoolList, 'id') , $this->schoolList );
		}
		return $this->schoolList;
	}
	
	public function getNameById($id){
		if( empty($this->schoolList) ){
			$this->getSchoolList();
		}
		return empty($this->schoolList[$id]) ? '' : $this->schoolList[$id]['name'];
	}
	
	public function incrementDevID($schoolID){
	    $res = $this->db->set('maxDevID','maxDevID + 1',FALSE)
	               ->where('id',$schoolID)
	               ->update($this->_table);
	    if( $res ){
            return $this->db->select('maxDevID')
                            ->where('id',$schoolID)
                            ->limit(1)
                            ->from($this->_table)
                            ->get()
                            ->row()
                            ->maxDevID;
	    }
	    return FALSE;
	}
	
}

